package com.itheima.dao.impl;

import com.itheima.dao.SingletonTemplate;
import com.itheima.dao.UserDao;
import com.itheima.dao.UserRowMapper;
import com.itheima.model.User;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

@Component("userDao")
public class UserDaoImpl implements UserDao {
    private  JdbcTemplate jdbcTemplate =SingletonTemplate.getJdbcTemplate();
    public void save(){
        System.out.println("userDao");
        JdbcTemplate jdbcTemplate = SingletonTemplate.getJdbcTemplate();
        String sql = "INSERT INTO user(NAME) VALUE(\"test\");";
        jdbcTemplate.execute(sql);
    }
    public User select(int id){
        String sql = "SELECT * FROM user WHERE id=?;";
        User user = jdbcTemplate.queryForObject(sql,new UserRowMapper(), id);
        return user;
    }

}
